package com.nami.common.domain.pojo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.nami.common.domain.entity.BaseEntity;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * 用户实体类
 *
 * @author chengh
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_user")
public class SysUser extends BaseEntity implements UserDetails {

    private static final long serialVersionUID = 7431409112743068259L;

    private Long id;

    private String deptId;

    private String username;

    private String password;

    private String nickName;

    private String userType;

    private String email;

    private String phoneNumber;

    private String sex;

    private String avatar;

    private String status;

    private String loginIp;

    private String loginDate;

    private LocalDateTime pwdUpdateDate;

    @TableField(exist = false)
    private List<String> roleKeys;

    @TableField(exist = false)
    private List<String> perms;

    /**
     * 获取用户权限信息
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    /**
     * 获取密码
     */
    @Override
    public String getPassword() {
        return this.password;
    }

    /**
     * 获取用户名
     */
    @Override
    public String getUsername() {
        return this.username;
    }

    /**
     * 是否过期
     *
     * @return boolean true:认证成功; false:过期
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 密码是否过期
     *
     * @return Boolean true: 认证成功; false: 过期
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 账户是否被锁定
     *
     * @return true: 认证成功; false: 账户锁定
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 账户是否可用
     *
     * @return true: 认证成功; false: 账户不可用
     */
    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public String toString() {
        return this.username;
    }

    @Override
    public int hashCode() {
        return username.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        System.out.println("调用了equals方法");
        if (obj instanceof SysUser) {
            return this.toString().equals(obj.toString());
        }
        return false;
    }

}

